package com.example.mybatisdemo1.controller;

import com.example.mybatisdemo1.dao.TestDao;
import com.example.mybatisdemo1.entity.UserPojo;
import com.example.mybatisdemo1.service.AirPortService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: xiaoqiang
 * @Description:
 * @Date: 2020/8/20
 * @Version: 1.0
 */
@RestController
@Slf4j
public class TestController {

    @Autowired
    TestDao testDao;

    @Autowired
    AirPortService airPortService;

    @RequestMapping("t1")
    public String t1() {
        MDC.put("mdc_key", "0000000000001");
        log.info("t1执行........");
        return "ok";
    }

    @RequestMapping("t2")
    public String t2() {
        UserPojo userPojo = new UserPojo();
        userPojo.setName("hello");
        userPojo.setPassword("123");
        int add = testDao.addUser(userPojo);
        return add + "";
    }

    @RequestMapping("t3")
    public List t3() {
        List<UserPojo> userList = testDao.getUserList(12);
        return userList;
    }

    @RequestMapping("/uploadAirportData.dc")
    public String uploadAirportData(HttpServletRequest request, HttpServletResponse response) {
        //这里只是做测试，读取本地excel，如果是线上，这里改下传参即可
        airPortService.doMethod(airPortService);
        return "ok";
    }

    //登陆接口
    @PostMapping("valid")
    public String fun(@RequestBody @Validated(value = {UserPojo.login.class}) UserPojo userPojo) {
        System.out.println(userPojo);
        return "ok";
    }

    //注册接口
    @PostMapping("reg")
    public String reg(@RequestBody @Validated UserPojo userPojo) {
        System.out.println(userPojo);
        return "ok";
    }

}
